package com.ichir.projects.uiflow.internal.executors;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;

import com.ichir.projects.uiflow.ApplicationContext;
import com.ichir.projects.uiflow.definition.FlowType;
import com.ichir.projects.uiflow.ui.api.IUiPart;

public class ExecutorsRegistry {

	private static Map<FlowType, IUiPartExecutor> executors = new HashMap<FlowType, IUiPartExecutor>();
	
	static {
	
		executors.put(FlowType.VIEW, new UIViewExecutor());
		executors.put(FlowType.ACTION, new UIActionExecutor());
		
	}
	
	/**
	 * 
	 * @param part
	 * @param context
	 * @param attributes
	 */
	public static void execute(final IUiPart part, FlowType type, final ApplicationContext context, final Map<String, Object> attributes) {
		final IUiPartExecutor executor = executors.get(type);
		Executors.newSingleThreadExecutor().execute(new Runnable() {
			@Override
			public void run() {
				executor.executeUiPart(part, context, attributes);
			}
		});
	}
}
